package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YCKOKO
 * Date: 2022-10-22
 * Time: 17:04
 */
public class AddOperation implements IOPeration{
    public void work(BookList bookList){
        //新增图书
        System.out.println("新增图书");
        System.out.println("请输入你要新增的图书名称：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        System.out.println("请输入你要新增的图书作者：");
        String author = scanner.nextLine();
        System.out.println("请输入你要新增的图书价格：");
        int price = scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入你要新增的图书类型：");
        String type = scanner.nextLine();
        Book book = new Book(name,author,price,type);
        //获取当前可以存放书的位置
        int currentSize = bookList.getUsedSize();
        //把图书新增到指定位置
        bookList.setBooks(book,currentSize);
        //图书的有效位置加1
        bookList.setUsedSize(currentSize+1);
        System.out.println("新增图书成功！");
    }
}
